package com.juzipi.demo.controller;


import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.juzipi.demo.service.UsersService;
import com.juzipi.demo.tools.PageResult;
import com.juzipi.demo.tools.Result;
import com.juzipi.demo.vo.UserBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UsersController {



    @Autowired
    private UsersService usersService;


    @PostMapping("all")
    public Result queryUsersByPage(
            @RequestParam(value = "pageNum",defaultValue = "1")Long pageNum,
            @RequestParam(value = "pageSize",defaultValue = "10")Long pageSize
    ){
        PageResult<UserBO> pageResult = usersService.queryUsersByPage(pageNum,pageSize);
        if (CollectionUtils.isEmpty(pageResult.getItems())){
            return Result.fail(404,"NOT_FOUND");
        }
        return Result.successData(pageResult);
    }




}
